<template>
  <div class="search_course_name">
    <el-select
      :value="classId"
      filterable
			@change="selectName"
      placeholder="请输入课程关键词"
    
      :loading="loading"
    >
      <el-option
        v-for="item in classList"
        :key="item.id"
        :label="item.teacherName"
        :value="item.id"
      >
      </el-option>
    </el-select>
  </div>
</template>

<script>
import { getTeachersByName,getAllTeacher } from "@/api/school/teacher";
export default {
  data() {
    return {
      classId: "",
      classList: [],
      loading: false,
      open: false,
    };
  },
 
  methods: {
    init(e) {
      this.classId = e ? e : '';
      console.log(this.classId, 'classId', e)
      this.classList = [];
      this.loading = false;
      this.open = false;
      this.getTeacherByName();
    },
    selectName(e) {
      // this.classList.forEach(item => {
      //   console.log("item:", item)
      //   if (item.id == e) {
      //     this.classId = item.teacherName || item.teacherNo
      //   }
      // })
      // console.log(e, '选择')
      this.classId = e;
      this.$emit("change", e);
    },
    remoteMethod(query) {
      this.loading = true;
      getTeachersByName({ teacherName: query }).then((res) => {
        console.log(res);
        this.loading = false;
        this.classList = res.data;
      });
    },
       //查询所有老师信息
    getTeacherByName(query) {
      getTeachersByName({teacherName:query}).then((res) => {
        this.loading = false;
        this.classList = res.data;
       }).catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.search_course_name {
  width: 100%;
  height: 100%;
}
</style>